
#Elecion Boric: 21 de Diciembre.
#Fourth wave: December 6 and 13
#Fifth wave: December 28, 2021 and January 4, 2022. 

#Plebiscito: September 4th
#First wave: August 30 and September 2 of 2022
#Post-election wave: 12 and 19

#Set English as default language
Sys.setlocale("LC_TIME", "English")

user <- "C:/Users/Matias/Dropbox/Proyectos/Fondecyt Participacion Electoral/Articulos/Electoral Winners y Plebiscito/"

#Base de Datos
dd <- data.frame(
  boric = as.Date(1:60, origin="2021-11-20"),
  rechazo = as.Date(1:60, origin="2022-08-05"),
  xvar = 2
)

#PLOT
png(filename=paste0(user, "Resultados/fig_fechas.png"), width=2400, height = 1800, 
    res=300)
par(mfrow=c(2,1))

#Presidencial
with(dd, plot(boric, rep(2,60), type="n", ylab="", xlab="", bty="n", yaxt="n", ylim=c(0,4),
              xlim=c(as.Date("2021-11-30"), as.Date("2022-01-15")),
              main="Presidential Runoff Election"))
abline(v=as.Date("2021-12-21"), col="red", lty=1)
polygon(x=c(as.Date("2021-12-06"), as.Date("2021-12-13"),
            as.Date("2021-12-13"), as.Date("2021-12-06")),
        y=c(0, 0, 4, 4), 
        col ='grey80', border=F)
polygon(x=c(as.Date("2021-12-28"), as.Date("2022-01-04"),
            as.Date("2022-01-04"), as.Date("2021-12-28")),
        y=c(0, 0, 4, 4), 
        col ='grey80', border=F)
#with(dd, lines(boric, rep(2,60), type="l", lty=4))
arrows(y0=2, y1=2, x0=as.Date("2021-12-01"), x1=as.Date("2022-01-13"), 
       lty=2)
text(x=as.Date("2021-12-09"), y=3.4, labels="Fieldwork \nWave 4", cex=.8)
text(x=as.Date("2021-12-31"), y=3.4, labels="Fieldwork \nWave 5", cex=.8)
text(x=as.Date("2021-12-22"), y=3.4, labels="Election \nDay", cex=.8, adj = c(0,1))


#Plebiscito
with(dd, plot(rechazo, rep(2,60), type="n", ylab="", xlab="", bty="n", yaxt="n", ylim=c(0,4),
              xlim=c(as.Date("2022-08-15"), as.Date("2022-09-30")),
              main="Constitutional Plebistice"))
abline(v=as.Date("2022-09-04"), col="red", lty=1)
polygon(x=c(as.Date("2022-08-30"), as.Date("2022-09-02"),
            as.Date("2022-09-02"), as.Date("2022-08-30")),
        y=c(0, 0, 4, 4), 
        col ='grey80', border=F)
polygon(x=c(as.Date("2022-09-12"), as.Date("2022-09-19"),
            as.Date("2022-09-19"), as.Date("2022-09-12")),
        y=c(0, 0, 4, 4), 
        col ='grey80', border=F)
#with(dd, lines(boric, rep(2,60), type="l", lty=4))
arrows(y0=2, y1=2, x0=as.Date("2022-08-16"), x1=as.Date("2022-09-28"), 
       lty=2)
text(x=as.Date("2022-08-31"), y=3.4, labels="Fieldwork \nWave 1", cex=.8)
text(x=as.Date("2022-09-15"), y=3.4, labels="Fieldwork \nWave 2", cex=.8)
text(x=as.Date("2022-09-05"), y=3.4, labels="Election \nDay", cex=.8, adj = c(0,1))
dev.off()

